-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes an error thrown when assigning to readOnly property 'toJSON' #1293
Conversation
…erty 'toJSON' this breaks my app when I try to create a document which is a dupe according to my compound index
those test failures don't seem like something I could have broken with my little change |
can you please add a test case that causes this to fail with the current driver, this will make it easier for me to accept this pull request. |
Still missing a test case that causes this to happen. Unfortunately I'm not going to merge this until I understand why you are experiencing this problem while there has been no other such issues from other users. |
@christkv thanks for reminding me. I was busy over the weekend, will try to make a test case in the next couple of days. No rush on merging it. Weird that others don't experience the same problems. |
closing due to no response |
please merge this, I'm seeing this problem too. |
please provide a test that reproduces this issue |
@andrewaarestad this was happening for me because I have used a package https://www.npmjs.com/package/error-tojson which extended Error.prototype. |
@christkv writing a repro test case would not be hard- just https://github.com/AVVS/error-tojson/blob/master/index.js before doing anything with mongo which returns an error. Is it worth it? P.S.: I've created a note on readme for error-tojson: AVVS/error-tojson#1 |
Writing it in the docs won't make a difference. I think you are on your own when monkey patching core JS classes. It's very much a no no thing to do as it causes unpredictable behavior in any package depending on it. |
Installed modules:
Fixes in "mongodb/lib/utils.js" (use try ... catch): /**
* Wrap a Mongo error document in an Error instance
* @ignore
* @api private
*/
var toError = function(error) {
if (error instanceof Error) return error;
var msg = error.err || error.errmsg || error.errMessage || error;
var e = MongoError.create({message: msg, driver:true});
// Get all object keys
var keys = typeof error == 'object'
? Object.keys(error)
: [];
for(var i = 0; i < keys.length; i++) {
try {
e[keys[i]] = error[keys[i]];
} catch(err) {
// continue
}
}
return e;
} |
this breaks my app when I try to create a document which is a dupe according to my compound index